const path = require('path');
const fs = require('fs');

function calcSizeSync(dirPath,cb){
    let fileSize=0
    let error=null
    function calc(dirPath,cb1){
        const statObj=fs.statSync(dirPath)
        if(statObj.isDirectory()){
            try {
                const files=fs.readdirSync(dirPath)
                let dirs=files.map(item=>{
                    return path.join(dirPath,item)
                })
                for (let i = 0; i < dirs.length; i++) {
                    calc(dirs[i],cb1)
                }
            } catch (err) {
                error=err
            }
        }else{
            fileSize+=statObj.size
            cb1&&cb1()
        }
    }
    calc(dirPath)
    cb(error,fileSize)
}

let dir = "C:\\Users\\ibbo\\Desktop\\1\\480p_265";

calcSizeSync(dir,function (err,size) {
    if (!err){
        size = (size/1024).toFixed(2)
    console.log(size)
    }
})